package com.itheima.health.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.health.resource.date.DateUtils;
import com.itheima.health.service.OrderSettingService;
import com.itheima.health.service.UserService;
import com.itheima.mapper.OrderSettingMapper;
import com.itheima.mapper.UserMapper;
import com.itheima.pojo.OrderSetting;
import com.itheima.pojo.Permission;
import com.itheima.pojo.Role;
import com.itheima.pojo.User;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;


@Service
@Transactional
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {




    @Override
    public User findUserDetailsInfoByUsername(String username) {
          //   user 账号密码      user--role  关键字      permisson  关键字
        //  1  user基本信息
       User user =  baseMapper.findUserInfoByUsername(username);

       //  2  根据用户id  查询  对应角色关键字
        Set<Role> roleList = baseMapper.findRoleInfoByUserId(user.getId());

        //  3.  通过角色id  查询 对应 权限信息
        for (Role role : roleList) {
           Set<Permission> permissionSet =  baseMapper.findPermissionInfoByRoleId(role.getId());
           role.setPermissions(permissionSet);
        }

        user.setRoles(roleList);

        return user;
    }
}
